package com.example;


import com.example.eventbus.consumor.ConsumerVerticle;
import com.example.eventbus.send.ProducerVerticle;
import com.example.verticle.MainVerticle;
import com.example.verticle.TestVerticle;
import io.vertx.core.CompositeFuture;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Application {
    private static final Logger LOGGER = LoggerFactory.getLogger(Application.class);

    public static void main(String[] args) {
        LOGGER.info("app init begin");
        Vertx vertx = Vertx.vertx();
//        vertx.deployVerticle(MainVerticle.class.getName());
//        vertx.deployVerticle(TestVerticle.class.getName());

        Promise<String> consumerPromise_1 = Promise.promise();
        Promise<String> consumerPromise_2 = Promise.promise();
        vertx.deployVerticle(ConsumerVerticle.class.getName(),new DeploymentOptions()
                .setConfig(new JsonObject().put("id","consumer-1")),consumerPromise_1);
        vertx.deployVerticle(ConsumerVerticle.class.getName(),new DeploymentOptions()
                .setConfig(new JsonObject().put("id","consumer-2")),consumerPromise_2);
        CompositeFuture.all(consumerPromise_1.future(),consumerPromise_2.future())
                .onSuccess(id->{
                    vertx.deployVerticle(ProducerVerticle.class.getName());
                }
        );

    }
}
